package cn.wolfcode.ssm.controller;

import cn.wolfcode.ssm.domain.CustomerTransfer;
import cn.wolfcode.ssm.qo.JsonResult;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.ICustomerTransferService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransfer")
public class CustomerTransferController {

    @Autowired
    private ICustomerTransferService customerTransferService;

   @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")QueryObject qo) {
        PageInfo<CustomerTransfer> pageInfo = customerTransferService.selctForPageResult(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "customerTransfer/list";
    }


    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id) {
            if (id != null) {
                customerTransferService.delete(id);
            }
            return new JsonResult();
    }


    //贴自定义注解
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTransfer dept) {
            if (dept.getId() != null) {
                customerTransferService.update(dept);
            } else {
                customerTransferService.save(dept);
            }
            return new JsonResult();
    }

}
